package 二叉树;

import java.util.Scanner;

public class Test {
    /*static class TreeNode{

        char val;
        TreeNode left;
        TreeNode right;
        public TreeNode (char val) {
            this.val=val;
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();
           TreeNode cur= createTree(str);
           inOrder(cur);
           i=0;
            System.out.println();
        }
    }
    // 中序遍历
    static void  inOrder(TreeNode root){
        if(root==null) {
            return;
        }
        inOrder(root.left);
        System.out.print(root.val+" ");
        inOrder(root.right);
    }
     static int i;
    public static TreeNode createTree(String str ) {
        TreeNode treeNode=null;
        if(str.charAt(i)!='#') {
            treeNode=new TreeNode(str.charAt(i));
            i++;
            treeNode.left=createTree(str);
            treeNode.right=createTree(str);
            return  treeNode;
        }else {
            i++;
            return null;
        }
    }*/
    public static void main(String[] args) {
        BinaryTree<Character> b = new BinaryTree<>();
        BinaryTree.Node<Character> A = new BinaryTree.Node<>('A');
        BinaryTree.Node<Character> B = new BinaryTree.Node<>('B');
        BinaryTree.Node<Character> C = new BinaryTree.Node<>('C');
        BinaryTree.Node<Character> D = new BinaryTree.Node<>('D');
        BinaryTree.Node<Character> E = new BinaryTree.Node<>('E');
        BinaryTree.Node<Character> F = new BinaryTree.Node<>('F');
        BinaryTree.Node<Character> G = new BinaryTree.Node<>('G');
        BinaryTree.Node<Character> H = new BinaryTree.Node<>('H');
        b.root = A;
        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        C.left = F;
        C.right = G;
     //   b.preOrder(A);
       //b.inOrder(A);
       //b.sizePlus(A);
        System.out.println(b.getLeafNodeCountPlus(A));
        System.out.println(b.funcGetLeafNodeCountPlus1(A));

    }
    public static void main4(String[] args) {
        BinaryTree<Character> b = new BinaryTree<>();
        BinaryTree.Node<Character> A = new BinaryTree.Node<>('A');
        BinaryTree.Node<Character> B = new BinaryTree.Node<>('B');
        BinaryTree.Node<Character> C = new BinaryTree.Node<>('C');
        BinaryTree.Node<Character> D = new BinaryTree.Node<>('D');
        BinaryTree.Node<Character> E = new BinaryTree.Node<>('E');
        BinaryTree.Node<Character> F = new BinaryTree.Node<>('F');
        BinaryTree.Node<Character> G = new BinaryTree.Node<>('G');
        BinaryTree.Node<Character> H = new BinaryTree.Node<>('H');
        b.root = A;
        A.left = B;
        A.right = C;
        B.left = D;
        B.right = E;
        C.left = F;
        C.right = G;
        D.left = H;

        b.preOrder1(A);
        b.inOrder1(A);
        b.funcGetLeafNodeCountPlus1(A);

          //  System.out.println(b.isCompleteTree(A));
    }
        public static void main3(String[] args) {
        BinaryTree<Integer> b = new BinaryTree<>();
        BinaryTree.Node<Integer> A = new BinaryTree.Node<>(1);
        BinaryTree.Node<Integer> B = new BinaryTree.Node<>(2);
        BinaryTree.Node<Integer> C = new BinaryTree.Node<>(2);
        BinaryTree.Node<Integer> D = new BinaryTree.Node<>(3);
        BinaryTree.Node<Integer> E = new BinaryTree.Node<>(3);
        BinaryTree.Node<Integer> F = new BinaryTree.Node<>(4);
        BinaryTree.Node<Integer> G = new BinaryTree.Node<>(4);
        A.left=B;
        A.right=C;
        B.left=D;
        C.right=E;
        D.left=F;
        E.right=G;
        System.out.println(b.isBalanced(A));
    }
    public static void main2(String[] args) {
        BinaryTree<Character> b = new BinaryTree<>();
        BinaryTree.Node<Character> A = new BinaryTree.Node<>('A');
        BinaryTree.Node<Character> B = new BinaryTree.Node<>('B');
        BinaryTree.Node<Character> C = new BinaryTree.Node<>('C');
        BinaryTree.Node<Character> D = new BinaryTree.Node<>('D');
        BinaryTree.Node<Character> E = new BinaryTree.Node<>('E');
        BinaryTree.Node<Character> F = new BinaryTree.Node<>('F');
        BinaryTree.Node<Character> G = new BinaryTree.Node<>('G');
        BinaryTree.Node<Character> H = new BinaryTree.Node<>('H');
        b.root = A;
        A.left = B;
        B.left = D;
        B.right = E;
        E.right = H;
        A.right = C;
        C.left = F;
        C.right = G;
        //b.levelOrder(A);
        b.invertTree(A);
        b.levelOrder(A);
    }
    public static void main1(String[] args) {
        BinaryTree<Character> b = new BinaryTree<>();
        BinaryTree.Node<Character> A = new BinaryTree.Node<>('A');
        BinaryTree.Node<Character> B = new BinaryTree.Node<>('B');
        BinaryTree.Node<Character> C = new BinaryTree.Node<>('C');
        BinaryTree.Node<Character> D = new BinaryTree.Node<>('D');
        BinaryTree.Node<Character> E = new BinaryTree.Node<>('E');
        BinaryTree.Node<Character> F = new BinaryTree.Node<>('F');
        BinaryTree.Node<Character> G = new BinaryTree.Node<>('G');
        BinaryTree.Node<Character> H = new BinaryTree.Node<>('H');
        b.root = A;
        A.left = B;
        B.left = D;
        B.right = E;
        E.right = H;
        A.right = C;
        C.left = F;
        C.right = G;
       /* System.out.println(b.size(A));
        b.sizePlus(A);
        System.out.println(b.size());
        b.sizePlus(A);
        System.out.println(b.size());
       */
        System.out.println(b.getLeafNodeCount(A));
        System.out.println(b.getLeafNodeCountPlus(A));
        System.out.println(b.getKLevelNodeCount(A,2));
        System.out.println(b.getKLevelNodeCountPlus(A,2));
        System.out.println(b.getHeight(A));
        System.out.println(b.find(A,'g'));
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.println();
    }

}
